package com.woniuxy.activiti.listener;

import com.woniuxy.activiti.service.FlowService;
import com.woniuxy.activiti.utils.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MyTaskListener implements TaskListener {

    @Override
    @DependsOn("springContextUtils")
    public void notify(DelegateTask delegateTask) {
        log.info("事件名称eventName=={}",delegateTask.getEventName());
        if(delegateTask.getEventName().equals("assignment")){
            System.out.println("进入方法中---------");
            System.out.println("getBean:"+ SpringContextUtil.getBean("flowService"));
            FlowService flowService = (FlowService) SpringContextUtil.getBean("flowService");
            log.info("流flowService={}",flowService);
            System.out.println("flowService----:"+flowService);
            flowService.createTaskEvent(delegateTask);
        }
    }
}
